<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
	body,html{
		margin: 0 auto;
		height:100%;
		width:100%;
		overflow:hidden;
	}
</style>
</head>
<body>
	<div class="divfrist" id="Role_mainDiv" style="width:100%;height:100%;">
						<div style="width:100%;height:0.7%;overflow:hidden;"></div>
						<div style="width:100%;height:98.5%;">
								<div style="width:0.4%;height:100%;float:left;overflow:hidden;"></div>
								<div style="width:99.2%;height:100%;float:left;">
									 <div class="allborder" style="overflow: auto;height:100%;max-height:100%;">
													<!--内容区 -->
											<div style="width:100%;height:100%;">		
													 <table  id="RoleTable" border="false"></table>
											</div>
											<div id="Role_tb" style="overflow: hidden; padding-left: 10px; padding-top: 5px;padding-bottom: 5px;">
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon-add',plain:true" onclick="window.Role.addRole()">增加角色</a>||	
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon-edit',plain:true" onclick="window.Role.updateRole()">编辑角色</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon-no',plain:true" onclick="window.Role.deleteRole()">删除角色</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon-ok',plain:true" onclick="window.Role.setRole(1)">启用角色</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon482',plain:true" onclick="window.Role.setRole(0)">禁用角色</a>||	    	
											</div>		
													<!--内容区 -->
									 </div>
								</div>
								<div class="width:0.37%;height:100%;float:left;overflow:hidden;"></div>
						</div>
						<div class="width:100%;height:0.6%;overflow:hidden;"></div>
	</div>
</body>
<script type="text/javascript">
(function(){
	//增加角色
	function addRole(){
		
		if($("#Role_addRole").length>0){
			$("#Role_addRole").window("open");
		}
		$('<div id="Role_addRole"></div>').window({
		    title: '增加角色', 		
		    iconCls:'icon-add', 
		    width:600,   
		    height: 450,   
		    resizable:true,
		    closed: true,   
		    draggable:false,
		    modal: true,
		    content:$('<div style="width:100%;height:100%;"></div>').load("${pageContext.request.contextPath}/html/system/roleAdd.jsp"),
			onClose:function(){
				$("#Role_addRole").window("destroy",true);
				loadRoleInit();
		    }
		});
		$("#Role_addRole").window("open");
		
	}
	//更新角色
	function updateRole(){
		
		var sysRole=$('#RoleTable').datagrid("getSelections");
		if(sysRole.length<=0||sysRole.length>=2){
			alert("只能一次选择一行角色进行编辑");
			return;
		}
		if($("#Role_addRole").length>0){
			$("#Role_addRole").window("open");
		}
		$('<div id="Role_addRole"></div>').window({
		    title: '编辑角色', 		
		    iconCls:'icon-edit', 
		    width:600,   
		    height: 450,   
		    resizable:true,
		    closed: true,   
		    draggable:false,
		    modal: true,
		    content:$('<div style="width:100%;height:100%;"></div>').load("${pageContext.request.contextPath}/html/system/roleAdd.jsp?roleId="+sysRole[0].roleId+"&r="+Math.random()*1000),
		    onClose:function(){
				$("#Role_addRole").window("destroy",true);
				
		    }
		});
		$("#Role_addRole").window("open");
		$('#RoleTable').datagrid("uncheckAll");
		
	}
	//初始化角色table
	function loadRoleInit(){
		var p= $('#RoleTable').datagrid('getPager');
		var limit=$(p).pagination("options").pageSize;
		var start=$(p).pagination("options").pageNumber;
		$.ajax({
			type : "POST",
			dataType:'text',
			url : '<%=request.getContextPath()%>/sys/sysRoleAction!getRoleList.action',
			data:{page:start,rows:limit},
			dataType:'json',
			success : function(msg){
				$('#RoleTable').datagrid("loadData",msg);
				$('#RoleTable').datagrid("uncheckAll");
				 
			}
		});
	}
	//创建角色table
	function createRoleTable(){
			$('#RoleTable').datagrid({
				fit: true,
				toolbar:"#Role_tb",
				singleSelect:false,
				queryParams:{},
				rownumbers: true,
				animate:true,
				striped: true,
				loadMsg:'正在加载数据',
				url: "${pageContext.request.contextPath}/sys/sysRoleAction!getRoleList.action",
				collapsible:true,
				idField:'roleId',
				fitColumns:true,
				columns:[[
				    {field:'roleId',checkbox:true,width:50},	
			  		{field:'roleName',title:'角色名称',width:120},
			  		{field:'roleState',title:'角色状态',formatter : function(value, row, index){
						if(row.roleState=="0"){
							return  '<font color="red">禁用</font>';
						}
						if(row.roleState=="1"){
							return  '<font color="green">启用</font>';
						}
						return "";
						},width:120},
			  		{field:'roleNote',title:'角色描述',width:120},
			  		{field:'roleCreateDate1',title:'创建时间',width:120}
			  		]],
					pagination:true
				});
	}
	//删除角色
	function deleteRole(){
		var sysRoles=$('#RoleTable').datagrid("getSelections");
		$.ajax({
			   type: "POST",
			   url: "${pageContext.request.contextPath}/sys/sysRoleAction!deleteRole.action",
			   data:{roles:obj2str(sysRoles)},
			   success: function(msg){
			    	if(msg=="success"){
			    		alert("删除成功");
			    		loadRoleInit();
			    	}else{
			    		alert("删除失败");
			    	}
			   }
		});
	}
	//启用禁用角色
	function setRole(temp){
		var sysRoles=$('#RoleTable').datagrid("getSelections");
		$.ajax({
			   type: "POST",
			   url: "${pageContext.request.contextPath}/sys/sysRoleAction!setRole.action",
			   data:{roles:obj2str(sysRoles),roleState:temp},
			   success: function(msg){
			    	if(msg=="success"){
			    		alert("操作成功");
			    		loadRoleInit();
			    	}else{
			    		alert("操作失败");
			    	}
			   }
		});
	}
	//注册所有事件
	window["Role"]={};
	window["Role"]["addRole"]=addRole;
	window["Role"]["updateRole"]=updateRole;
	window["Role"]["deleteRole"]=deleteRole;
	window["Role"]["setRole"]=setRole;

	$(function(){	
		$.parser.parse('#Role_mainDiv'); 
		createRoleTable();
	});
})();

</script>
</html>